import datetime

from django.conf import settings
from django.conf.urls.defaults import *

from views import *
from form_views import *

urlpatterns = patterns('',
    # Equivalent to direct_to_template
    ('^$', DirectView()),
    # Adding a static variables in context, in *class* or in *instance*
    # Overriding the first with the second
    ('^welcome/$', EnrichedView()),
    ('^other/$', EnrichedView(site="OtherPlace.com")),
    # Adding a dynamic variables in context, in *calls*
    ('^hello/(?P<name>\w+)/$', DynamicView()),
    ('^bye/(?P<name>\w+)/$', DynamicView(greeting="Bye")),
    # Adding authentification
    ('^private/$', PrivateView()),
    # Adding variables in context at call time
    ('^now/$', ContextView()),
    ('^now/(?P<name>\w+)/$', ContextView()),
    # inheriting ! Even more DRY...
    # adding more vars in context according given arguments passed through URL
    ('^now/(?P<name>\w+)/(?P<cap>cap|nocap)/$', ComplexView(cap=True)),
    # change type of response
    ('^forbidden/$', ForbiddenView()),
    # stop process at any point
    ('^time/(?P<shift>-?\d+)/$', ProcessView()),
    # Need full HTML ? not response object ?
    # simply call view instance with make_response=False
    ('^about/raw/$', RawHTMLView()),
    # all inclusive: all options and settings available
    ('^all/(?P<kwarg1>\w+)/(?P<kwarg2>\w+)/$', AllView(time=datetime.datetime.now())),
)
       
urlpatterns += patterns('',                
    # Simplest form
    ('^form/simplest/$', SimplestForm()),
    ('^form/success/$', SucessView()),
    # Register form
    ('^form/register/$', RegisterForm()),
    ('^form/registered/$', RegisterView()),
    # Cutting form
    ('^form/cut/$', CutForm()),
    # Ajax form
    ('^ajax/$', AjaxView()),
    ('^form/ajax/$', AjaxForm()),
    # All inclusive
    ('^form/all/$', AllFormView()),
    ('^form/all/form/$', AllForm()),
    ('^form/all/results/(?P<integer>\d+)/$', ResultsView()),
    # use cases
    ('^form/comments/$', AddingCommentView()),
    ('^polls/$', PollView()),

    # django batteries
    (r'^accounts/login/$', 'obviews.fallbacks.login'),
    (r'^accounts/logout/$', 'obviews.fallbacks.logout'),
    (r'^accounts/register/$', register),
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)

if not settings.APPENGINE:
    from django.contrib import admin
    admin.autodiscover()
    urlpatterns += patterns('',                
        (r'^admin/doc/', include('django.contrib.admindocs.urls')),
        (r'^admin/', include(admin.site.urls)),
    )
